//
//  InforViewController.m
//  ScrollView
//
//  Created by Shin Stupid on 12/25/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "InforViewController.h"

@implementation InforViewController


@synthesize mscrollviewPortrait;
static InforViewController *InforViewControllerInstance=nil;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
         self.tabBarItem.image = [UIImage imageNamed:@"tabbar_history.png"];
       // UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
        //[self addLable];
        InforViewControllerInstance=self;
        
    }
    return self;
}
+(InforViewController*)getStoreViewControllerInstance
{
    return InforViewControllerInstance;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    // Do any additional setup after loading the view from its nib.
    [self addLable];
    if (IS_IPHONE5) {
        
    }
    else
    {
        
       
        mscrollviewPortrait.frame = CGRectMake(0, 0, 320, 460);
        mscrollviewPortrait.contentSize = CGSizeMake(320, 500-80);
    }
    
    
    
    [mscrollviewPortrait setBackgroundColor:[UIColor clearColor]];
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    BOOL isCurrentlyLandscapeView = UIDeviceOrientationIsLandscape(deviceOrientation);
    if(isCurrentlyLandscapeView==TRUE)
    {
        
        
        
        [self setpositionLableLandScape:TRUE];
    }
    else
    {
        
        
        [self setpositionLableLandScape:FALSE];

    }
    
    [self setLableLanguageInforScene];
    
}
-(void)setLableLanguageInforScene
{
   // NSLog(@"APP_DELEGATE.langId =%@",APP_DELEGATE.langId);
    NSString *STR=APP_DELEGATE.langId;//@"eng";//@"vn"
    Title.text=GET_STRING(@"TITLE", STR); 
    Descripton.text=GET_STRING(@"DESCRIPTION", STR);
    Notice.text=GET_STRING(@"NOTICE", STR);
}
-(void)addLable
{
    //// title
    Title = [[UILabel alloc ] init];
    Title.textAlignment =  UITextAlignmentCenter;
    Title.textColor = [UIColor whiteColor];
    Title.backgroundColor=[UIColor clearColor];
    Title.font = [UIFont fontWithName:@"Arial" size:(19.0)];
    Title.frame=CGRectMake(0, 0, 256, 100);
    [mscrollviewPortrait addSubview:Title];
    /// Desctiption
    Descripton = [[UILabel alloc ] init];
    Descripton.textAlignment =  UITextAlignmentLeft;
    Descripton.textColor = [UIColor whiteColor];
    Descripton.backgroundColor=[UIColor clearColor];
    Descripton.font = [UIFont fontWithName:@"Arial" size:(17.0)];
    Descripton.frame=CGRectMake(0, 0, 200, 100);
    [mscrollviewPortrait addSubview:Descripton];
    ////Notice
    Notice= [[UILabel alloc ] init];
    Notice.textAlignment =  UITextAlignmentLeft;
    Notice.textColor = [UIColor whiteColor];
    Notice.backgroundColor=[UIColor clearColor];
    Notice.font = [UIFont fontWithName:@"Arial" size:(15.0)];
    Notice.frame=CGRectMake(0, 0, 310,140 );
    Notice.lineBreakMode = UILineBreakModeWordWrap;
    Notice.numberOfLines = 5;
    [mscrollviewPortrait addSubview:Notice];
  
}
-(void)setpositionLableLandScape:(BOOL)isLandScape
{
    if (IS_IPHONE5) {
        
    }
    else
    {
     
        if(isLandScape==TRUE)
        {
            Title.center=CGPointMake(250, 30);///center
            Descripton.center=CGPointMake(110, 80);/// left
            Notice.frame=CGRectMake(5, 100, 470, 80);/// left
        }
        else
        {
            Title.center=CGPointMake(160, 30);/// center
            Descripton.center=CGPointMake(110, 100);/// left
            Notice.frame=CGRectMake(5, 120, 310, 140);/// left
        }
    }
    
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    
    return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
      
        [self changeTheViewToPortrait:YES andDuration:duration];
        
    }
    else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
        
       [self changeTheViewToPortrait:NO andDuration:duration];
    }
}
- (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{
    
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:duration];
    
    if(portrait){
        //change the view and subview frames for the portrait view
        
        mscrollviewPortrait.contentSize = CGSizeMake(320, 500-80);
        [self setpositionLableLandScape:FALSE];
        
    }
    else{   
        //change the view and subview  frames for the landscape view
        mscrollviewPortrait.contentSize = CGSizeMake(320, 500-180);
        [self setpositionLableLandScape:TRUE];
        
    }
    
    [UIView commitAnimations];
}
#pragma mark - Action delegate
-(IBAction)selectWebsite:(id)sender
{
    
}

-(void)dealloc
{
    [super dealloc];
    SAFE_RELEASE(Title);
    SAFE_RELEASE(Descripton);
     SAFE_RELEASE(Notice);
}
- (void)viewDidUnload
{
    [super viewDidUnload];
}
@end
